#!/bin/sh
# PCP QA Test No. 1503
# Exercise Broken Pipe handling in some python tools.
#
# Copyright (c) 2022 Red Hat.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

test -f $PCP_BINADM_DIR/pcp-ps  || _notrun "No support for python tools"

_cleanup()
{
    cd $here
    $sudo rm -rf $tmp $tmp.*
}

status=0	# success is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

# real QA test starts here
for tool in ps pidstat
do
    echo "== Checking pcp $tool" | tee -a $seq_full
    ( pcp $tool | head ) > $tmp.$tool 2>&1
    if grep -q ^Traceback $tmp.$tool
    then
        echo "Failed!"
        cat $tmp.$tool | tee -a $seq_full
        status=1
    else
        cat $tmp.$tool >> $seq_full
    fi
done

# success, all done
exit
